<template>
  <el-dialog ref="form" :title="title" :visible="visiable" append-to-body @close="close" destroy-on-close>
    <div>
      <el-form :model="form" label-width="100px">
        <el-form-item label="用户id">
          <el-input v-model="form.id" disabled></el-input>
        </el-form-item>
        <el-form-item :label="title" required>
          <el-input v-model="form[column]" @input="change"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer algin">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import RequestRemote from '../../../utils/request'
export default {
  name: 'duplicateCheckCoupon',
  props: {
    visiable: {
      type: Boolean,
      default: false
    },
    row: {
      type: Object,
      default: {}
    },
    // 第二个字段 要更新的
    column: {
      type: String,
      default: ''
    },
    requestURL: {
      type: String,
      default: ''
    },
    title: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      form: {
        id: 0
      }
    }
  },
  mounted() { },

  watch: {
    visiable: {
      handler(value) {
        if (value) {
          this.form.id = this.row.id;
          this.form[this.column] = this.row[this.column];
        }
      },
      deep: true
    }
  },

  methods: {
    cancel() {
      this.close()
    },
    submitForm() {
      if (!this.form[this.column]) {
        this.$message.error('请填写数据')
        return
      }
      RequestRemote.post(this.requestURL, this.form).then((res) => {
        this.$message.success('操作成功')
        this.$emit('close', false)
        this.$emit('updateData', this.row, this.column, this.form[this.column])
      })
    },

    close() {
      this.$emit('close', false)
    },
    change(e) {
      console.log("e", e);
      this.$forceUpdate()
    }
  }
}
</script>

<style>
.algin {
  text-align: center;
}
</style>
